package com.zzh.tree;


public class No104_maxDepth {
    public static void main(String[] args) {
        No104Solution solution = new No104Solution();
        int i = solution.maxDepth(TreeNode.initTree());
        System.out.println(i);
    }
}

class No104Solution {
    private int max = 0;

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        dfs(root, 1);
        return max;
    }

    public void dfs(TreeNode root, int depth) {
        if (root.right == null && root.left == null) {
            if (depth > max) {
                max = depth;
            }
            return;
        }
        if (root.left != null) {
            dfs(root.left, depth + 1);
        }
        if (root.right != null) {
            dfs(root.right, depth + 1);
        }

    }
}
